<template>
    <view class="page-content" style="overflow-y:auto; background:#F6F6F6;min-height:100vh;max-height:calc(100vh - 50rpx);">
        <scroll-view scroll-y="true" class="auto-h main-scroll m-l-20 m-r-20" style="height: 100%;">
            <navbar @clickLeft="toHome" fixed leftIcon="left" title="资产映射" shadow></navbar>
            
            <view class="m-t-70 tips success">
            	请通过验证手机号，获取资产、贡献池、团队快照信息<br />
				并确认以当前钱包地址作为收款地址<br />
				如果多次提交会以最后一次提交的地址为准<br />
            </view>
            <view v-if="checkDone == 0" class="p-l-14 p-r-14 bg-fff p-t-20 p-b-20" style="border-radius: 19px;box-shadow: 0px 2px 10px 0px rgba(58, 73, 145, 0.13);">
                <view class="h30 view flex-row align-center justify-between p-l-15">
                    <input style="border:0;height:60rpx;"  v-model="mobile" placeholder="输入已在神龙实名手机"/>
                </view>
                <view class="h30 view flex-row align-center justify-between p-l-15 p-r-15 m-t-14">
                    <input style="border:0;height:60rpx;"  v-model="code" placeholder="填入验证码"/>
                    <div @click="getCode" style="color:#6082FF;">获取验证码</div>
                </view>
            </view>
            <el-button @click="codeCheck" v-if="checkDone == 0" class="btn-c m-t-40" block style="border-radius: 12px !important;" type="primary">查询快照信息</el-button>
			<view class="tips success">
				90%用户“确认数据无误”后<br />
				数据将统一映射到用户登记的地址<br />
				<view class="bold">{{defaultWallet.address}}</view>
				不需要重复质押即可开始产出收益。
			</view>
			<!-- scroll view -->
			<!--<scroll-view>-->
			<view v-if="showOld == 1" class="p-l-14 p-r-14 bg-fff p-t-20 m-t-20 p-b-20" style="border-radius: 19px;box-shadow: 0px 2px 10px 0px rgba(58, 73, 145, 0.13);">
			   <view class="m-b-6 bold c_0a1">基础信息</view>
			   <view>
				   <view v-if="userData.kyc != null">
					   <view v-for="(item,index) in userData.kyc" :key="index">
						   <view>{{item.title}}: {{item.value}}</view>
					   </view>
					   <hr />
				   </view>
				   uid: {{userData.uid}}<br />
				   邀请码:  {{userData.invite_code}}<br />
				   团队业绩:{{userData.business_vol_team}}<br />
				   个人单数: {{userData.business_vol_self_count}}<br />
				   个人业绩: {{userData.business_vol_self}}<br />
				   挖矿收益: {{userData.mine_reward}}<br />
			   </view>
			</view>
			<view v-if="showOld == 1" class="p-l-14 p-r-14 bg-fff m-t-20 p-t-20 p-b-20" style="border-radius: 19px;box-shadow: 0px 2px 10px 0px rgba(58, 73, 145, 0.13);">
			   <view class="m-b-6 bold c_0a1">资产信息</view>
			   <view v-if="userData.balance">
				   DSX: [流通:{{userData.balance[0].online}}] [锁定:{{userData.balance[0].lock}}] [总额:{{userData.balance[0].total}}]<br />
				   YPT: [流通:{{userData.balance[1].online}}] [锁定:{{userData.balance[1].lock}}] [总额:{{userData.balance[0].total}}]<br />
				   CHB: [流通:{{userData.balance[2].online}}] [锁定:{{userData.balance[2].lock}}] [总额:{{userData.balance[0].total}}]<br />
			   </view>
			</view>
			<view v-if="showOld == 1" class="p-l-14 p-r-14 bg-fff m-t-20 p-t-20 p-b-20" style="border-radius: 19px;box-shadow: 0px 2px 10px 0px rgba(58, 73, 145, 0.13);">
			   <view class="m-b-6 bold c_0a1">CHB贡献池</view>
			   <view>
				   [社区创建数:{{userData.chb.teams.count}}, 共支付{{userData.chb.teams.cost}} CHB] <br />
				   [社区股权:{{userData.chb.teams.share}}] <br />
				   [总贡献值:{{userData.chb.kuang.power}}] [总收益:{{userData.chb.kuang.reward}}]<br />
				   <view v-if="userData.dig.length > 0">
					   <hr />
					   贡献值获取情况：<br />
					   <view v-for="(item,index) in userData.dig" :key="index">
					   		<view>{{item.insert_time}}</view>
							<view>[获得算力：{{item.suan_total}}]</view>
							<br />
					   </view>
				   </view>
			   </view>
			</view>
			<el-button @click="verifyTwice" v-if="checkDone == 0 && showOld != 0" class="btn-c m-t-40" block style="border-radius: 12px !important;" type="primary">确认数据无误</el-button>
			<!--</scroll-view>-->
		</scroll-view>
    </view>
</template>

<script>
import { mapMutations, mapState } from 'vuex'
import navbar from '@/components/uni-nav-bar'
import uniIcons from '@/components/uni-icons/uni-icons'
import uniSwiperDot from '@/components/uni-swiper-dot/uni-swiper-dot'
import  uniEasyinput from '@/components/uni-easyinput/uni-easyinput'
import elButton from '@/components/el-button/el-button'
import noData from '@/components/noData/noData'
import sibList from '@/components/sib-list/sib-list.vue'
import { aboutWallet } from "@/common/businessCommon";
import {getSms,findByAddress,verifyDone,mobileFindData,getMobileCode} from '@/apis/wallet.js';

export default {
    components: {
      navbar,
      uniEasyinput,
      uniIcons,
      uniSwiperDot
        
	},
    data() {
        return {
			current: 0,
			mode: 'round',
			verify: 0,
			checkDone: 0,
			showOld: 0,
			mobile:"",
			code:"",
			userData:{}
        }
    },
	computed: {
		...mapState(['defaultWallet']),
	},
	onShow() {
	  this.getStatus();
	},
    methods: {
		toHome(){
			uni.reLaunch({
			    url: '/pages/home/index',
			});
		},
		async getCode(){
			if(this.mobile.length < 8){
				this.$showToast('请填入正确的手机号');
				return
			}
			let account = await getMobileCode(this.defaultWallet.address,this.mobile);
			if(account.data){
				console.log('msg',account.data);
				this.$showToast('您的验证码已经发送成功');
			}
		},
		async getStatus(){
			let status = await findByAddress(this.defaultWallet.address);
			console.log('status',status);
			if(status.data != 0){
				//用户已经存在了
				this.userData = status.data;
				if(status.data != 0){
					this.showOld = 1;
					this.verify = 1;
					this.checkDone = 1;
				}
			}	
		},
		async verifyTwice(){
			let status = await verifyDone(this.defaultWallet.address,this.mobile);
			console.log('status',status);
			if(status.data != 0){
				//用户已经存在了
				this.verify = 1;
				this.checkDone = 1;
			}	
		},
		async codeCheck(){
			let check = await mobileFindData(this.defaultWallet.address,this.mobile,this.code);
			if(check.data){
				this.userData = check.data;
				if(check.data != 0){
					this.showOld = 1;
				}
			}
		}
    }
};
</script>

<style lang="scss" scoped>
.bar1-title {
    color:#3C3C3C;
    font-size: 32rpx;
}

page {
    background: #F6F6F6;
}
.left-bar-item {width: 100%;height:68px;display: flex;align-items: center;justify-content: center;}
.left-bar-item .image{
    width:30px;
    height: 30px;
}
.left-bar-item.active {
    background: #F6F6F6;
}
.btn-c {
    display: block;
    margin-top:56rpx;
    width: 100%;
    height: 96rpx;
    line-height: 78rpx;
    font-size: 40rpx;
}
.tips .bold{
	word-break: break-all;
	font-size: 16px;
	color: #000;
	margin: 6px 6px;
}
.zuji-item {background: #fff;border-radius: 10px;color:#6781FF;}
.fix-bottom {width: 100vw;height: 100px;background: #fff;bottom: 0;left: 0;padding-top:32rpx;position: fixed;}
</style>
